package me.helllp.book.concurrent.ch05;

import java.nio.ByteBuffer;

import com.lmax.disruptor.RingBuffer;

public class ProducerDisruptor {
	private final RingBuffer<PCDataDisruptor> ringBuffer;
	
	public ProducerDisruptor(RingBuffer<PCDataDisruptor> ringBuffer) {
		this.ringBuffer = ringBuffer;
	}
	
	public void pushData(ByteBuffer bb){
		long sequence = ringBuffer.next();
		try {
			PCDataDisruptor event = ringBuffer.get(sequence);
			event.setValue(bb.getLong(0));
		} finally {
			ringBuffer.publish(sequence);
		}
	}
}
